package GUI;

import Model.Customer;
import Model.SalesOrder;

import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;

public class OrderTableModel extends DefaultTableModel {

    private ArrayList<SalesOrder> data;

    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }

    public void setData(ArrayList<SalesOrder> data)
    {
        this.data = data;
        fireTableDataChanged();
    }

    public ArrayList<SalesOrder> getData() {
        return data;
    }

    @Override
    public int getColumnCount() {
        return 5;
    }

    @Override
    public int getRowCount()
    {
        if(data == null)
        {
            return 0;
        }
        else
        {
            return data.size();
        }
    }

    @Override
    public String getColumnName(int column) {
        String columnName = "";
        switch(column)
        {
            case 0:
                columnName = "ID";
                break;
            case 1:
                columnName = "Date";
                break;
            case 2:
                columnName = "Delivery status";
                break;
            case 3:
                columnName = "Delivery dato";
                break;
            case 4:
                columnName = "Customer";
                break;
        }
        return columnName;
    }

    @Override
    public Object getValueAt(int row, int column)
    {
        Object value = null;
        switch(column)
        {
            case 0:
                value = data.get(row).getId();
                break;
            case 1:
                value = data.get(row).getDate();
                break;
            case 2:
                value = data.get(row).getDeliveryStatus();
                break;
            case 3:
                value = data.get(row).getDeliveryDate();
                break;
            case 4:
                value = data.get(row).getCustomer();
                break;
        }

        return value;
    }
}
